#include"epoll.h"
#include"logger.h"


struct epoll_event ev;
//创建epoll
int epollCreate(int *epfd, int sockfd){

  
    *epfd = epoll_create(1);
    if(*epfd == -1){
        perror("epoll_create");
        LOG_ERROR("epoll_create failed");
        return -1;
    }
    LOG_INFO("epoll_create success");
    return 0;
}
//添加epoll事件
int epollAdd(int epfd, int fd){
    ev.events = EPOLLIN;
    ev.data.fd = fd;
    int ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
    if(ret == -1){
        perror("epoll_ctl");
        LOG_ERROR("epoll_ctl add failed, fd = %d", fd);
        return -1;
    }
    LOG_INFO("epoll_ctl add success, fd = %d", fd);
    return 0;
}
//删除epoll事件
int epollDel(int epfd, int fd){
    int ret = epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
    if(ret == -1){
        perror("epoll_ctl");
        LOG_ERROR("epoll_ctl del failed, fd = %d", fd);
        return -1;
    }
    LOG_INFO("epoll_ctl del success, fd = %d", fd);
    return 0;
}